package cn.swu.homework1

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import android.widget.EditText
import android.widget.ProgressBar
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import java.util.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val username=findViewById<EditText>(R.id.username)
        val password=findViewById<EditText>(R.id.password)


    }
    fun onclick(view:View)
    {
        AlertDialog.Builder(this)

            .setTitle("please choose one")
            .setMessage("whether you will logi?")
            .setPositiveButton("sure"){d,w->toLogin()}
            .setNegativeButton("quit"){d,w-> Toast.makeText(this, "exit suceesfully", Toast.LENGTH_SHORT).show()}
            .show()

    }

    private fun toLogin() {
       val process=findViewById<ProgressBar>(R.id.timeline)
        process.visibility=View.VISIBLE
        process.progress=0
        val timer=Timer()
        val context=this
        val task =object :TimerTask(){
            override fun run() {
               process.progress=process.progress+1
                if(process.progress==10)
                {
                    timer.cancel()
                    Handler(Looper.getMainLooper()).post{
                        process.visibility=View.GONE
                        intent = Intent(context,ListActivity::class.java)
                        startActivity(intent)
                    }
                }
            }
        }//位置要在timertask的后面
        timer.schedule(task,0,500)
    }
}